using Unity.Entities;
using Unity.VisualScripting;
using UnityEngine;
using Random = Unity.Mathematics.Random;

namespace Tutorial4_Singleton
{
    public struct RandomSingleton : IComponentData
    {
        public Random RandomInstance;
    }
    
    // 单例，确保只存在一个RandomSingletonAuthoring
    public class RandomSingletonAuthoring : Common.Singleton<RandomSingletonAuthoring>
    {
        public uint Seed = 1;
    }

    public class RandomSingletonBaker : Baker<RandomSingletonAuthoring>
    {
        public override void Bake(RandomSingletonAuthoring authoring)
        {
            // 获取或创建单例实体
            Entity entity = GetEntity(TransformUsageFlags.None);
            AddComponent(entity, new RandomSingleton()
            {
                RandomInstance = new Random(authoring.Seed)
            });
        }
    }
}
